package flowSum;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author caoxiaofeng
 * @date 2021-07-14 22:52
 */
public class FlowBean implements Writable {

    private  long upFlow;
    private  long downFlow;
    private  long sumFlow;

    // 空参构造，为了后续反射用
    public FlowBean(){
        super();
    }

    public FlowBean(long upFlow,long downFlow){
        super();
        this.downFlow = downFlow;
        this.upFlow = upFlow;
        sumFlow = upFlow + downFlow;
    }


    // 序列化 与 反序列化的顺序要保持一致
    // 序列化方法
    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(upFlow);
        out.writeLong(downFlow);
        out.writeLong(sumFlow);
    }

    // 反序列化方法
    @Override
    public void readFields(DataInput in) throws IOException {
        upFlow = in.readLong();
        downFlow = in.readLong();
        sumFlow = in.readLong();
    }

    public long getUpFlow() {
        return upFlow;
    }

    public void setUpFlow(long upFlow) {
        this.upFlow = upFlow;
    }

    public long getDownFlow() {
        return downFlow;
    }

    public void setDownFlow(long downFlow) {
        this.downFlow = downFlow;
    }

    public long getSumFlow() {
        return sumFlow;
    }

    public void setSumFlow(long sumFlow) {
        this.sumFlow = sumFlow;
    }

    @Override
    public String toString() {
        return
                "upFlow=" + upFlow + "\t" +
                "downFlow=" + downFlow  + "\t"+
                "sumFlow=" + sumFlow + "\t";
    }

    public void set(long upFlow, long downFlow) {
        this.upFlow = upFlow;
        this.downFlow = downFlow;
        this.sumFlow = upFlow + downFlow;
    }
}
